package com.shop.service.impl;

import com.shop.dao.FactoryDao;
import com.shop.domain.Factory;
import com.shop.domain.Page;
import com.shop.service.FactoryService;
import com.shop.util.IDUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * FactoryServiceImpl
 * Created by heqianqian on 2017/7/10.
 */
@Service
public class FactoryServiceImpl implements FactoryService<Factory> {

    @Resource
    private FactoryDao factoryDao;

    @Override
    @SuppressWarnings("unchecked")
    public List<Factory> findPage(Page page) {
        return factoryDao.findPage(page);
    }

    @Override
    @SuppressWarnings("unchecked")
    public List<Factory> find(Map paraMap) {
        return factoryDao.find(paraMap);
    }

    @Override
    @SuppressWarnings("unchecked")
    public List<Factory> listFactory() {
        Map<String, Object> map = new HashMap<>();
        map.put("state", 1);
        return factoryDao.find(map);
    }

    @Override
    public Factory get(Serializable id) {
        return (Factory) factoryDao.get(id);
    }

    @Override
    @SuppressWarnings("unchecked")
    public void insert(Factory factory) {
        //设置UUID
        factory.setFactoryId(IDUtils.getId());
        factory.setState("1");
        factoryDao.insert(factory);
    }

    @Override
    @SuppressWarnings("unchecked")
    public void update(Factory factory) {
        factoryDao.update(factory);
    }

    @Override
    public void deleteById(Serializable id) {
        factoryDao.deleteById(id);
    }

    @Override
    public void delete(Serializable[] ids) {
        factoryDao.delete(ids);
    }

    @Override
    @SuppressWarnings("unchecked")
    public void start(Serializable[] ids) {
        Map map = new HashMap();
        map.put("ids", ids);
        map.put("state", 1);
        factoryDao.updateState(map);
    }

    @Override
    @SuppressWarnings("unchecked")
    public void stop(Serializable[] ids) {
        Map map = new HashMap();
        map.put("ids", ids);
        map.put("state", 0);
        factoryDao.updateState(map);
    }
}
